<template>
  <el-dialog title="添加员工" :visible.sync="visible" width="30%" @close="resetForm">
    <el-form :model="form" label-width="100px" ref="form">
      <el-form-item label="账号" prop="username">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="员工姓名" prop="name">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input v-model="form.phone"></el-input>
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <el-select v-model="form.gender" placeholder="请选择性别">
          <el-option label="男" value="1"></el-option>
          <el-option label="女" value="0"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="身份证号" prop="idNumber">
        <el-input v-model="form.idNumber"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="submitForm">保存</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      form: {
        username: "", // 账号
        name: "",     // 员工姓名
        phone: "",    // 手机号
        gender: "",   // 性别
        idNumber: "", // 身份证号
      },
    };
  },
  methods: {
    open() {
      this.visible = true;
    },
    resetForm() {
      this.$refs.form.resetFields();
    },
    submitForm() {
      this.$emit("submit", this.form); // 将表单数据传递给父组件
      this.visible = false;
    },
  },
};
</script>